#ifndef _SCENEMANAGER_H
#define _SCENEMANAGER_H

#include <cassert>
#include <cstdlib>
#include <list>
#include <string>
#include <iostream>
#include <map>

#include "reseatable_reference.h"
#include "scenenode.h"

class SceneManager
{
	public:
		SceneManager();
		
		bool initialize(const std::string & datapath, std::ostream & log);
		
		// this loads the specified file into the destination node but doesn't affect the scene
		// if you want the loaded node in the scene you'll need to add it.
		bool load(SceneNode & destination, const std::string & file, std::ostream & log) const;
		
		bool save(const std::string & file, std::ostream & log);
		
		reseatable_reference <SceneNode> addNode(const SceneNode & newNode, const SceneNode * beforeNodeIfPossible = NULL) {return root.addNode(newNode, beforeNodeIfPossible);}
		reseatable_reference <const SceneNode> getNodeType(const std::string & type) const;
		SceneNode & getRoot() {return root;}
		bool deleteNode(const SceneNode & node) {return root.deleteNode(node);} // linear time
		SceneNode * getParent(const SceneNode & node) {return root.getParent(node);} // linear time
		const SceneNode * getNextSibling(const SceneNode & node) const {return root.getNextSibling(node);} // linear time
		
		typedef std::map <std::string, SceneNode> nodeTypes_type;
		const nodeTypes_type & getNodeTypes() const {return nodeTypes;}
		
	private:
		SceneNode root;
		nodeTypes_type nodeTypes;
};

#endif
